package com.ctsi.framework.mybatis.support;

import com.ctsi.framework.mybatis.dialect.DialectConfiguration;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.context.annotation.*;

/**
 * 配置 Mybatis Dao
 *
 * @author zhangjw
 *
 */

@Configuration
public class MybatisDaoConfiguration {
    private static final Logger log = LoggerFactory.getLogger(MybatisDaoConfiguration.class);

    @Configuration
    @AutoConfigureBefore(MybatisAutoConfiguration.class)
    @Import({DialectConfiguration.class})
    @ComponentScan(basePackages = {"com.ctsi.framework.mybatis.interceptor"})
    public static class InterceptorConfig {

    }

    @Bean
    @Primary
    public MybatisGenericDao mybatisGenericDao(SqlSessionFactory sqlSessionFactory){
        MybatisGenericDao dao = new MybatisGenericDao();
        dao.setSqlSessionFactory(sqlSessionFactory);
        return dao;
    }

    @Bean
    @Primary
    public MybatisBatchDao mybatisBatchDao(SqlSessionTemplate sqlSessionTemplate){
        MybatisBatchDao dao = new MybatisBatchDao();
        dao.setSqlSessionTemplate(sqlSessionTemplate);
        return dao;
    }

    @Bean
    public VoTemplate voTemplate(){
        return new VoTemplate();
    }

}
